package hot100;

import DTO.TreeNode;

public class pathSum {
    int ret = 0;

    public int pathSum(TreeNode root, int targetSum) {
        if(root == null) {
            return 0;
        }
        depth(root,targetSum,0);
        pathSum(root.left, targetSum);
        pathSum(root.right, targetSum);
        return ret;
    }

    public void depth(TreeNode root,int targetSum,long pre) {
        if(root == null) {
            return;
        }
        pre = pre + root.val;
        if(pre == targetSum) {
            ret++;
        }
        depth(root.left,targetSum,pre);
        depth(root.right,targetSum,pre);

    }
}
